<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>A WebSocket Demo</title>
</head>
<body>
    <h1>Node.js WebSocket Demo</h1>
    SEND: <input type="text" id="sendText" />
    <button id="sendBtn">Send</button>
    <br />    
    RECV： <span id="recv"></span>
    <script>
        var webSocket = new WebSocket("ws://localhost:8001/")
        webSocket.onopen=function(){
            document.getElementById("recv").innerHTML="Connected";
        }
        webSocket.onclose=function(){
            document.getElementById("recv").innerHTML="Closed";
        }
        webSocket.onmessage=function(e){
            document.getElementById("recv").innerHTML=e.data;
        }
        document.getElementById("sendBtn").onclick=function(){
            webSocket.send(document.getElementById("sendText").value);
        }
    </script>
</body>
</html>